package com.hhly.rabbitmq.work;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import com.hhly.rabbitmq.RabbitMQUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;

public class NewTask {
	 public  static final String TASK_QUEUE_NAME = "task_queue";
  public static void main(String[] args) {
	  try {
			Channel channel = RabbitMQUtil.getChannel();
			Map<String, Object> map = new HashMap<>();
			map.put("x-max-priority", 10);
			map.put("x-ha-policy", "all");
			channel.queueDeclare(TASK_QUEUE_NAME, false, false, false, map); 
			int i = 0;
			for(;;){
				Thread.sleep(1000);
				BasicProperties properties =  new AMQP.BasicProperties.Builder().priority(new Random().nextInt(10)).deliveryMode(2).build();
				//MessageProperties.PERSISTENT_TEXT_PLAIN
				String message = "Hello World!" + i++;
				channel.basicPublish("", TASK_QUEUE_NAME,properties, message.getBytes());
				System.out.println(message+"|"+System.currentTimeMillis());
			}
		} catch (IOException | InterruptedException e) {
			e.printStackTrace();
		}
}
}
